package com.training.java.core.collections.car.pre15;

/*The purpose of this class is to demonstrate how equals and hashcode can be overridden to check the objects equality. 
 *  
 * @author Satya
 *
 */
public class Tv {

	private String company;
	private String type;
	private boolean enabled3D;
	private int price;

	public Tv(String company, String type, boolean enabled3D, int price) {
		this.company = company;
		this.type = type;
		this.enabled3D = enabled3D;
		this.price = price;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setEnabled3D(boolean enabled3d) {
		enabled3D = enabled3d;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public String getCompany() {
		return company;
	}

	public String getType() {
		return type;
	}

	public boolean isEnabled3D() {
		return enabled3D;
	}

	public int getPrice() {
		return price;
	}

	/**
	 * Here the requirement is
	 * "company, type (LCD, LED, Plasma) and price together define equality"
	 * finding the equality by overriding the equals and hashCode
	 */

	@Override
	public boolean equals(Object obj) {

		// checking the parameter is real time object or not.
		// if it is not real object, it should
		// return False.

		if (obj instanceof Tv)

		{
			Tv television3 = (Tv) obj; // Casting
			return this.company.equals(television3.company)
					&& this.type.equals(television3.type);// &&
															// this.price.equals(television1.type));

		} else {
			return false;

		}

	}// end of equals method

	// Overriding the hashCode

	@Override
	public int hashCode() {
		return company.hashCode() + type.hashCode(); // + price.hashCode() ;
	}

}
